package dao.auth.mybatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.auth.Roles;
import model.auth.Users;
import model.auth.UsersRoles;

import org.springframework.stereotype.Repository;

import core.base.page.Page;
import core.base.page.PageRequest;
import dao.MyBatisBaseDao;
import dao.auth.UsersRolesDao;

@Repository("auth.UsersRolesDao")
public class UsersRolesDaoImpl extends MyBatisBaseDao implements UsersRolesDao {

	public int deleteById(Long id) {
		return getSqlSessionTemplate().delete("auth.UsersRolesMapper.deleteById", id);
	}

	public UsersRoles getById(Long id) {
		return (UsersRoles) getSqlSessionTemplate().selectOne("auth.UsersRolesMapper.getById", id);
	}

	public int insert(UsersRoles model) {
		return getSqlSessionTemplate().insert("auth.UsersRolesMapper.insert", model);
	}

	public List<Roles> getRolesByUserId(Long userId) {
		List<Roles> roles = getSqlSessionTemplate().selectList("auth.UsersRolesMapper.getRolesByUserId", userId);
		return roles;
	}

	public List<Users> getUsersByRoleId(Long roleId) {
		List<Users> users = getSqlSessionTemplate().selectList("auth.UsersRolesMapper.getUsersByRoleId", roleId);
		return users;
	}

	public Page<Roles> queryRolesForPage(PageRequest<Map> pageReq) {
		return super.queryForPage(pageReq, "auth.UsersRolesMapper.queryRolesForPage");
	}

	public Page<Users> queryUsersForPage(PageRequest<Map> pageReq) {
		return super.queryForPage(pageReq, "auth.UsersRolesMapper.queryUsersForPage");
	}

}
